package com.action;

import java.util.*;

import com.dao.BaseDAO;
import com.entity.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class FlatAction extends ActionSupport {
	Flat data;
	BaseDAO dao = new BaseDAO();

	public String add() {
		dao.add(data);
		return show();
	}

	public String del() {
		dao.del(data);
		return show();
	}

	public String show() {
		ActionContext.getContext().put("all", dao.show("from Flat"));
		return SUCCESS;
	}
	
	public String find() {
		String hql = "from Flat where 1=1";
		List params = new ArrayList();
		if(!"".equals(data.getArea())){
			hql+=" and area=?";
			params.add(data.getArea());
		}
		if(!"".equals(data.getNo())){
			hql+=" and no=?";
			params.add(data.getNo());
		}
		if(!"".equals(data.getMgr())){
			hql+=" and mgr=?";
			params.add(data.getMgr());
		}
		ActionContext.getContext().put("all", dao.find(hql,params.toArray()));
		return SUCCESS;
	}
	
	public String modify(){
		Flat flat = (Flat)dao.findByID(Flat.class, data.getId());
		ActionContext.getContext().put("record",flat);
		return "modify";
		
	}
	
    public String edit(){
    	Object obj = dao.findByID(Flat.class,data.getId());
    	ActionContext.getContext().put("record", obj);
    	return "modify";
    }
    

	public String update() {
		dao.update(data);
		return show();
	}


	public Flat getData() {
		return data;
	}

	public void setData(Flat data) {
		this.data = data;
	}


}
